package com.mtt.thirdapi.yanxuan.controller;

import com.mtt.thirdapi.common.exception.MttErpException;
import com.mtt.thirdapi.yanxuan.service.YXOpenApiService;
import com.mtt.thirdapi.common.api.R;
import com.mtt.thirdapi.yanxuan.vo.ApplyInfoVo;
import com.mtt.thirdapi.yanxuan.vo.YxRefundOfferExpressVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

/**
 * 严选售后服务
 */
@RestController
@RequestMapping("yanxuan")
@Slf4j
@Validated
public class YXAfteSaleController {
    @Autowired
    YXOpenApiService yxOpenApiService;

    /**
     * 渠道发起售后服务请求
     * 发货后45天内，渠道确认收货后可发起售后服务请求，现只支持退货申请
     * （同一sku在同一时刻只能有一个售后申请存在），
     * @param applyInfoVo
     * @return
     */
    @PostMapping("/refundOrderApply")
    public R refundOrderApply(@RequestBody ApplyInfoVo applyInfoVo){
        return yxOpenApiService.handleRefundOrderApply(applyInfoVo);
    }

    /**
     * 渠道取消售后服务请求
     * @return
     */
    @PostMapping("/refundOrderCancel")
    public R refundOrderCancel(String applyId){
        return yxOpenApiService.handleRefundOrderCancel(applyId);
    }

    /**
     * 渠道绑定售后寄回物流单号
     * @param yxRefundOfferExpressVo
     * @return
     */
    @PostMapping("/refundOrderOfferExpress")
    public R refundOrderOfferExpress( @RequestBody @Valid YxRefundOfferExpressVo yxRefundOfferExpressVo) throws MttErpException {
        return yxOpenApiService.handleRefundOrderOfferExpress(yxRefundOfferExpressVo);
    }

    /**
     * 查询严选售后申请详情
     * @param applyId
     * @return
     */
    @GetMapping("refundOrderDetail")
    public R refundOrderDetail(@NotBlank(message = "{required}") String applyId){
        return yxOpenApiService.handleRefundOrderDetail(applyId);

    }
}
